<?php
header("Content-Type: text/html; charset=utf-8");
define("mysql_host","localhost");//mysql主机
define("mysql_user","root");//mysql用户名
define("mysql_pass","");//mysql密码
define("mysql_dbname","wwwcqfyxcom");//指定mysql数据库
define("cachename","fyx");//指定缓存名称

//连接数据库
function DBConn(){
	global $mysqli;
	$mysqli = new mysqli(mysql_host,mysql_user,mysql_pass,mysql_dbname);
	$mysqli->query("set names utf8;");
	if (mysqli_connect_errno()){
		die("连接数据库失败");
	}
	return $mysqli;
}

DBConn();
require "./Classes/PHPExcel.php";
$objPHPExcel = new PHPExcel();
//var_dump($objPHPExcel);
$objSheet=$objPHPExcel->getActiveSheet();
$objSheet->setTitle('多乐');

$sql='select * from tim_tuan where laiyuan="27"';

if(  ($result= $mysqli->query($sql)) && ( $result->num_rows>0 )     ){
	$ctr_num=1;
	while( $row=$result->fetch_array()  ){

		/*var_dump($row);*/
		echo 'xx='."A{$ctr_num}".'<br>';

		$objSheet->setCellValue("A{$ctr_num}",$row['id'])->setCellValue("B{$ctr_num}",$row['realname']);
		$ctr_num+=1;	
	}



}

$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel2007");


	   
$objWriter->save('demo.xlsx');


//var_dump($sql);

die();
require "./Classes/PHPExcel.php";
$objPHPExcel = new PHPExcel();
//var_dump($objPHPExcel);
$objSheet=$objPHPExcel->getActiveSheet();
$objSheet->setTitle('多乐');


/*$objSheet->setCellValue("A1","姓名")->setCellValue("B1","分数");
$objSheet->setCellValue("A2","张三")->setCellValue("B2","50");*/
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel2007");


	   
$objWriter->save('demo.xlsx');
?>
